import request from '@/utils/request'

const API_BASE = '/api/recordings'

export default {
  // 获取录制文件列表
  getRecordings(date = null) {
    const params = date ? { date } : {}
    return request({
      url: `${API_BASE}/list`,
      method: 'get',
      params
    })
  },

  // 获取可用日期列表
  getAvailableDates() {
    return request({
      url: `${API_BASE}/dates`,
      method: 'get'
    })
  },

  // 获取目录内容
  getDirectoryContents(path = '') {
    return request({
      url: `${API_BASE}/directory`,
      method: 'get',
      params: { path }
    })
  },

  // 转换文件为HLS格式
  convertFile(filePath) {
    return request({
      url: `${API_BASE}/convert`,
      method: 'post',
      data: { file_path: filePath }
    })
  },

  // 自动转换旧文件
  autoConvert() {
    return request({
      url: `${API_BASE}/auto-convert`,
      method: 'post'
    })
  },

  // 获取播放URL
  getPlayUrl(relativePath) {
    return `${API_BASE}/play/${encodeURIComponent(relativePath)}`
  },

  // 删除录制文件
  deleteRecording(filePath) {
    return request({
      url: API_BASE,
      method: 'delete',
      data: { file_path: filePath }
    })
  },

  // 获取录制统计信息
  getStatistics() {
    return request({
      url: `${API_BASE}/statistics`,
      method: 'get'
    })
  }
}